package com.miao.config;

import com.miao.server.WebsocketSign;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author <a href="https://gitee.com/a-tom-is-cry">Xing</a>
 * @Date 2024/9/10 10:33
 * @Description
 */
@Slf4j
public class InitWebsocket {

    private WebsocketSign websocketSign;

    /**
     * @param port 监听端口号
     */
    public InitWebsocket(Integer port) {
        try {
            websocketSign = new WebsocketSign(port);
            System.out.println(websocketSign.port);
            Thread thread = new Thread(websocketSign);
            thread.start();
        } catch (Exception e) {
            log.info("消息推送服务初始化失败，失败原因:{}", e.getMessage());
        }
    }

    /**
     * @param port 监听端口号
     * @param path 访问路径
     */
    public InitWebsocket(Integer port, String path) {
        try {
            websocketSign = new WebsocketSign(port, path);
            Thread thread = new Thread(websocketSign);
            thread.setName("websocket");
            thread.start();
        } catch (Exception e) {
            log.info("消息推送服务初始化失败，失败原因:{}", e.getMessage());
        }
    }
}
